

#ifndef __TOUCH_INPUT_H
#define __TOUCH_INPUT_H

#include "f32.h"
#include "vec2.h"
#include "rect.h"

enum TouchEvent
{
	TOEV_DOWN,
	TOEV_MOVE,
	TOEV_UP,
	TOEV_CANCEL,
	TOEV_CLEAR,
	
	TOEV_INVALID
};

class CTouchInput
{
private:
	TouchEvent			m_Event;
	vec2				m_Position;
	vec2				m_LastPosition;
	vec2				m_Velocity;
	vec2				m_DownPos;
	int					m_Taps;
	long				m_DownTime;
	long				m_UpTime;
	int					m_NumInputs;

	boolean				m_NoAcceleromterInfo;
	float				m_Accelerometer0[3];
	float				m_Accelerometer1[3];
	boolean				m_Shake;
	boolean				m_RaiseUp;
	int					m_Shakes;
	
	float				m_curAccelX;
	float				m_curAccelY;
	float				m_curAccelZ;
	float				m_lastAccelX;
	float				m_lastAccelY;
	float				m_lastAccelZ;
	
public:
	CTouchInput( void );
	void HandleEvent( TouchEvent event, const vec2 * pPosition, long time, int taps, int numInputs );
	void HandleAccelerometer( float x, float y, float z );
	void Reset();
	void Clear();

	boolean HitsRect( const _Rect * pRect ) const;
	boolean PressRect( const _Rect * pRect ) const;
	
public:
	TouchEvent GetEvent( void ) const { return m_Event; }
	int GetTaps( void ) const { return m_Taps; }
	vec2&  GetVelocity( void ) { return m_Velocity; }
	vec2&  GetPosition( void ) { return m_Position; }
	vec2&  GetLastPosition( void ) { return m_LastPosition; }
	vec2&  GetDownPos( void ) { return m_DownPos; }
	long GetActionDuration( void ) { return m_UpTime - m_DownTime; }
	int GetNumInputs( void) { return m_NumInputs; }
	
	boolean IsShake( void ) { return m_Shake; }
	boolean IsRaiseUp() { return m_RaiseUp; }
	float GetShakeX(){return m_curAccelX - m_lastAccelX;}
	float GetShakeY(){return m_curAccelY - m_lastAccelY;}
	float GetShakeZ(){return m_curAccelZ - m_lastAccelZ;}
	float GetAccelX(){return m_curAccelX;}
	float GetAccelY(){return m_curAccelY;}
	float GetAccelZ(){return m_curAccelZ;}
	boolean IsOverTurn();
	void ResetAccelerometer( void ) { m_NoAcceleromterInfo = TRUE; }
	const float * GetAcceleration( void ) const { return m_Accelerometer1; }
};

#endif // __TOUCH_INPUT_H